<template>
	<div class="content">
		<div class="clear">
			<Form :model="query" label-position="left" :label-width="100">
				<Input v-model="query.id" class="w200 m-r10" placeholder="提现编号" />
				<Input v-model="query.uuid" class="w200 m-r10" placeholder="个人ID" />
				<Input v-model="query.userName" class="w200 m-r10" placeholder="用户名" />
				<Select placeholder="请选择提现状态" class="w200 m-r10" v-model="query.state">
					<Option value="0">全部</Option>
					<Option value="1">转赠</Option>
					<Option value="2">待审核</Option>
					<Option value="3">转账中</Option>
					<Option value="4">成功</Option>
					<Option value="5">不通过</Option>
				</Select>
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getConditionQuery">查询</Button>
			</Form>
		</div>
		<fieldset v-for="(item,index) of walletInfo" :key="index">
			<legend v-text="item.coinName"></legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>总钱包地址：
								<span class="blue" v-text="item.supperAddress == null ? '#' : item.supperAddress">0</span>
							</td>
							<td>余额：
								<span class="blue" v-text="item.balance == null ? '#' : Fixed(item.balance, 4) + ' ' + item.supperName">0</span>
							</td>
							<td>代币余额：
								<span class="blue" v-text="item.token == null ? '#' : Fixed(item.token, 4) + ' ' + item.tokenName">0</span>
							</td>
							<td>累计转赠：
								<span class="blue" v-text="item.outerNum == null ? '0.00' : Fixed(item.outerNum,4)">0</span>
							</td>
							<td>累计实现提现：
								<span class="blue" v-text="item.outerNum == null ? '#' : Fixed(item.outerNum,4)">0</span>
							</td>
							<td>累计平台手续费：
								<span class="blue" v-text="item.appFee == null ? '#' : Fixed(item.appFee, 4)">0</span>
							</td>
						</tr>
						<tr>
							<td>累计实际手续费：
								<span class="blue" v-text="item.actualFee == null ? '#' : Fixed(item.actualFee, 4)">0</span>
							</td>
							<td>累计待审核数量：
								<span class="blue" v-text="item.thinkOuter == null ? '0.00' : item.thinkOuter">0</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
			<!-- <fieldset>
			<legend>汇总USDT</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td v-for="(item,index) in walletInfo" :key="index"><span v-text="'累计转入' + item.name + '：'"></span>
								<span class="blue" v-text="Fixed(item.sum,8)">0</span>
							</td>
							<td>
								累计提现:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计提现手续费:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计实际手续费:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计转赠:
								<span class="blue">{{ }}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset> -->

			<!-- <fieldset>
			<legend>汇总EMP</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td v-for="(item,index) in walletInfo" :key="index"><span v-text="'累计转入' + item.name + '：'"></span>
								<span class="blue" v-text="Fixed(item.sum,8)">0</span>
							</td>
							<td>
								累计提现:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计提现手续费:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计实际手续费:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计转赠:
								<span class="blue">{{ }}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset> -->

		<div style="position: relative;">
			<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon>导出
		</Button>
		</div>
		<Table stripe :columns="columns" :data="conditionQuery" ref="table" :loading="loading2"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
		<Modal v-model="model" title="确认操作" :loading="loading" @on-ok="asyncOK">
			<p>是否同意审核通过?</p>
		</Modal>
		<Modal v-model="modal2" title="输入审核密码" :mask-closable="false"  @on-cancel="cancel">
			<Form>
				<Input type="password" v-model="pass" placeholder="请输入审核密码" />
			</Form>
			<div slot="footer">
				<Button type="text" size="large" @click="$router.go(-1)">取消</Button>
				<Button type="primary" size="large" @click="asyncOK2">确定</Button>
			</div>
		</Modal>
	</div>
</template>
<script>
export default {
  data () {
    return {
      dcShow: false,
      loading2: false,
      jsonData: [],
      walletInfo: null, // 总钱包信息
      moneySummary: '', // 提币汇总
      dataValue: ['', ''], // 时间段值
      query: {
        id: '', // 提现编号
        uuid: '', // 用户名
        state: '', // 选择提现状态
        userName: ''
      },
      conditionQuery: [], // 条件查询的结果
      info: null, // 总条数
      page: 1, // 页数
      pageSize: 20, // 每页多少条
      current: 1,
      model: false,
      modal2: true,
      pass: '',
      loading: false,
      modelIndex: '', // 审核成功时候需要用到的 ID
      value: '', // 审核失败的时候填入的值
      downList: [],
      detailList: [],
      columns: [{
        title: '提现编号',
        key: 'tradeId',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.tradeId == null ? '#' : params.row.tradeId)
        }
      },
      {
        title: '个人ID',
        key: 'uuid',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.uuid == null ? '#' : params.row.uuid)
        }
      },
      {
        title: '用户名',
        key: 'userName',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.userName == null ? '#' : params.row.userName)
        }
      },
      {
        title: '币种类型',
        key: 'coinId',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.coinId == null ? '#' : this.coinIdFormat(params.row.coinId))
        }
      },
      {
        title: '到账地址',
        key: 'toAddress',
        align: 'center',
        width: 320,
        render: (h, params) => {
          return h('div', params.row.toAddress == null ? '#' : params.row.toAddress)
        }
      },
      {
        title: '提现数量',
        key: 'num',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.num == null ? '#' : this.Fixed(params.row.num, 4))
        }
      },
      {
        title: '平台手续费',
        key: 'appFee',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.appFee == null ? '#' : this.Fixed(params.row.appFee, 4))
        }
      },
      {
        title: '到账数量',
        key: 'actualNum',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.actualNum == null ? '#' : this.Fixed(params.row.actualNum, 4))
        }
      },
      {
        title: '实际手续费',
        key: 'actualFee',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.actualFee == null ? '#' : this.Fixed(params.row.actualFee, 8))
        }
      },
      {
        title: '提现状态',
        key: 'statusId',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.statusId == null ? '#' : params.row.statusId == 1 ? '转赠' : params.row.statusId == 2 ? '待审核' : params.row.statusId == 3 ? '转账中' : params.row.statusId == 4 ? '成功' : params.row.statusId == 5 ? '审核不通过' : '#')
        }
      },
      {
        title: '备注',
        key: 'remark',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.remark == null ? '#' : params.row.remark)
        }
      },
      {
        title: '提交时间',
        key: 'createTime',
        align: 'center',
        sortable: true,
        render: (h, params) => {
          return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
        }
      },
      {
        title: '审核操作',
        key: 'action',
        width: 150,
        align: 'center',
        render: (h, params) => {
          if (params.row.statusId == 2) {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    // 把记录 ID 传给审核按钮
                    this.removeSuccess(params.row.id)
                  }
                }
              }, '通过'),
              h('Button', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                on: {
                  click: () => {
                    // 把记录 ID 传给审核按钮
                    this.removeError(params.row.id)
                  }
                }
              }, '失败')
            ])
          } else if (params.row.statusId == 1) {
            return h('div', [
              h(
                'Button', {
                  props: {
                    type: 'primary',
                    size: 'small',
                    disabled: true
                  },
                  style: {
                    marginRight: '5px'
                  }
                },
                '自动审核	'
              )
            ])
          } else {
            return h('div', [
              h(
                'Button', {
                  props: {
                    type: 'primary',
                    size: 'small',
                    disabled: true
                  },
                  style: {
                    marginRight: '5px'
                  }
                },
                '已审核'
              )
            ])
          }
        }
      }
      ]
    }
  },
  mounted () {
    this.$Message.config({ // 配置弹窗的位置
      top: 250
    })
    this.getWalletInfo() // 获取总钱包信息
    this.getPass()
    this.getQuery()
  },  
  methods: {
    cancel(){
      this.$router.go(-1)
    },
    getPass () {
      this.axios.get('/admin/accounting/withdraw/pass').then(res => {
        
        if (res.data.code == 200) {
          if (res.data.data) {
            this.modal2 = false
            console.log(111);
            this.getQuery() // 提现审核列表查询
          }
        }
      })
    },
    getWalletInfo () { // 获取总钱包信息
      let token = localStorage.getItem('mytoken')
      this.axios.get('/admin/accounting/withdraw/sum').then(res => {
        if (res.data.code == 200) {
          this.walletInfo = res.data.data
        }
      })
    },
    getQuery () { // 提现审核列表查询
      this.loading2 = true
      let token = localStorage.getItem('mytoken')
      let spy
      if (this.query.state == 0) {
        spy = ''
      } else {
        spy = this.query.state
      }
      let params = this.qs.stringify({
        pn: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        tradeId: this.query.id, // 转账编号
        uuid: this.query.uuid, // 用户 uuid
        coinId: 0,
        userName: this.query.userName,
        statusId: spy, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })
      console.log(params);
      this.axios.post('/admin/accounting/withdraw/info', params).then(res => {
        console.log(res);
        if (res.data.code == 200) {
          this.conditionQuery = res.data.data.records
          this.info = res.data.data.total
          this.loading2 = false
        }
      })
    },
    cuctGetQuery (page) { // 提现审核列表分页查询
      this.loading2 = true
      let spy
      if (this.query.state == 0) {
        spy = ''
      } else {
        spy = this.query.state
      }
      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        pn: page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        tradeId: this.query.id, // 转账编号
        uuid: this.query.userName, // 用户 uuid
        coinId: 0,
        userName: this.query.userName,
        statusId: spy,
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })
      this.axios.post('/admin/accounting/withdraw/info', params).then(res => {
        console.log(res);
        if (res.data.code == 200) {
          this.conditionQuery = res.data.data.records
          this.info = res.data.data.total
          this.loading2 = false
        }
      })
    },
    getConditionQuery () { // 提现审核列表条件查询
      this.loading2 = true
      let spy
      let token = localStorage.getItem('mytoken')
      if (this.query.state == 0) {
        spy = ''
      } else {
        spy = this.query.state
      }
      this.page = 1
      let params = this.qs.stringify({
        pn: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        tradeId: this.query.id, // 转账编号
        uuid: this.query.uuid, // 用户 uuid
        userName: this.query.userName,
        statusId: spy, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        coinId: 0,
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })
      this.axios.post('/admin/accounting/withdraw/info', params).then(res => {
        if (res.data.code == 200) {
          this.conditionQuery = res.data.data.records
          this.info = res.data.data.total
          this.loading2 = false
        }
      })
    },
    exportData () { // 导出
      this.jsonData = []
      this.dcShow = true
      this.axios.post('/admin/accounting/withdraw/info', this.qs.stringify({
        pn: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        tradeId: this.query.id, // 转账编号
        uuid: this.query.uuid, // 用户 uuid
        statusId: this.query.state == 0 ? '' : this.query.state, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        userName: this.query.userName,
        coinId: 0,
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })).then(res => {
        if (res.data.code == 200) {
          this.axios.post('/admin/accounting/withdraw/info', this.qs.stringify({
            pn: 1, // 当前页【可选，默认1】
            size: res.data.data.total, // 每页记录数【可选，默认20】
            tradeId: this.query.id, // 转账编号
            uuid: this.query.uuid, // 用户 uuid
            statusId: this.query.state == 0 ? '' : this.query.state, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
            userName: this.query.userName,
            coinId: 0,
            startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
            endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
          })).then(res => {
            if (res.data.code == 200) {
              this.downList = res.data.data.records
              this.downList.forEach((row, index) => {
                this.downList[index].createTime = this.downList[index].createTime == null ? '#' : this.stringToTime(this.downList[index].createTime)
                this.downList[index].statusId = this.downList[index].statusId == null ? '#' : this.downList[index].statusId == 1 ? '转赠' : this.downList[index].statusId == 2 ? '待审核' : this.downList[index].statusId == 3 ? '转账中' : this.downList[index].statusId == 4 ? '成功' : this.downList[index].statusId == 5 ? '审核不通过' : '#'

                this.downList[index].tradeId = this.downList[index].tradeId == null ? '#' : this.downList[index].tradeId
                this.downList[index].uuid = this.downList[index].uuid == null ? '#' : this.downList[index].uuid
                this.downList[index].userName = this.downList[index].userName == null ? '#' : this.downList[index].userName
                this.downList[index].toAddress = this.downList[index].toAddress == null ? '#' : this.downList[index].toAddress
                this.downList[index].num = this.downList[index].num == null ? '#' : this.Fixed(this.downList[index].num, 4)
                this.downList[index].appFee = this.downList[index].appFee == null ? '#' : this.Fixed(this.downList[index].appFee, 4)
                this.downList[index].actualNum = this.downList[index].actualNum == null ? '#' : this.Fixed(this.downList[index].actualNum, 4)
                this.downList[index].actualFee = this.downList[index].actualFee == null ? '#' : this.Fixed(this.downList[index].actualFee, 8)
                this.downList[index].remark = this.downList[index].remark == null ? '#' : this.downList[index].remark

                this.jsonData.push({
                  tradeId: this.downList[index].tradeId,
                  uuid: this.downList[index].uuid,
                  userName: this.downList[index].userName,
                  coinId: this.coinIdFormat(this.downList[index].coinId),
                  toAddress: this.downList[index].toAddress,
                  num: this.downList[index].num,
                  appFee: this.downList[index].appFee,
                  actualNum: this.downList[index].actualNum,
                  actualFee: this.downList[index].actualFee,
                  statusId: this.downList[index].statusId,
                  remark: this.downList[index].remark,
                  createTime: this.downList[index].createTime
                })
              })
              let str = `提现编号,个人ID,用户名,币种类型,到账地址,提现数量,平台手续费,到账数量,实际手续费,提现状态,备注,提交时间\n`
              this.downLoad(this.jsonData, str, '提现审核')
            }
          })
        }
      })
    },
    getTime (daterange) { // 处理时间段时间格式
      this.dataValue = daterange
    },
    removeSuccess (index) { // 弹出审核提示
      this.model = true
      this.modelIndex = index
    },
    asyncOK () { // 审核通过,其中的 index 是上面传来的记录 ID
      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: this.modelIndex,
        statusId: 6, // 通过6
        remark: ''
      })
      this.axios.post('/admin/accounting/withdraw', params).then(res => {
        if (res.data.code == 200) {
          setTimeout(() => {
            this.model = false
            this.$Message.info(res.data.msg)
            this.getQuery()
            //							this.getQuery2();
          }, 500)
        }
      })
    },
    asyncOK2 () {
      this.axios.post('/admin/accounting/withdraw/pass', this.qs.stringify({
        auditPass: this.pass
      })).then(res => {
        this.pass = ''
        if (res.data.code == 200) {
          this.modal2 = false
          this.getQuery() // 提现审核列表查询
        }
      })
    },
    removeError (id) {
      this.$Modal.confirm({
        title: '审核失败？',
        render: (h) => {
          return h('Input', {
            props: {
              value: this.value,
              autofocus: true,
              placeholder: '请输入审核失败的原因...'
            },
            on: {
              input: (val) => {
                this.value = val // 当前输入的内容,传给下面的确定按钮
              }
            }
          })
        },
        onOk: () => { // 弹框的确定按钮
          let token = localStorage.getItem('mytoken')
          let params = this.qs.stringify({
            id: id,
            statusId: 5,
            remark: this.value
          })
          this.axios.post('/admin/accounting/withdraw', params).then(res => {
            if (res.data.code == 200) {
              this.$Message.info(res.data.msg)
              this.getQuery()
              this.getQuery2()
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
	/deep/ .ivu-modal {
		top: 30%;
	}
</style>
